home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 2632 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.0 KB  |  52 lines

  1. Path: newshost.lanl.gov!tanmoy
  2. From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Problem with c code, please help!
  5. Date: 22 Jan 1996 19:22:54 GMT
  6. Organization: Los Alamos National Laboratory
  7. Message-ID: <TANMOY.96Jan22122254@qcd.lanl.gov>
  8. References: <surgsw-1901960148530001@128.206.206.86> <4e0hn0$e80@spanky.pls.ov.com>
  9. NNTP-Posting-Host: qcd.lanl.gov
  10. Mime-Version: 1.0
  11. Content-Type: text
  12. In-reply-to: glenn@ov.com's message of 22 Jan 1996 17:32:16 GMT
  13.  
  14. --text follows this line--
  15. In article <4e0hn0$e80@spanky.pls.ov.com> glenn@ov.com
  16. (Fletcher.Glenn@ov.com) writes: 
  17. <snip>
  18.    >#include <stdio.h>
  19.    >
  20.    >main()
  21.    >{
  22.    >   int i=0;
  23.    >   char  word[100], c;
  24.    >   printf("Enter a word:   ");
  25.    >   while( (c = getchar()) != '\n')  {
  26.    >      *word = c;
  27.       ^^^^^
  28.    Problem #1, word is not a pointer.  You can't dereference it.  If you
  29.    wish to use a pointer into the "word" array, you need to create and
  30.    initialize the pointer.
  31.  
  32. Please read the FAQ before posting incorrect opinions. word is not a
  33. pointer, but it _decays_ to a pointer value (aka rvalue) except when
  34. used as an immediate operand of & or sizeof. In particular *word is
  35. exactly the same as word[0].
  36.  
  37. (In a previous post, I mistakenly wrote that an array always decays to
  38. a pointer under these circumstances. Technically, this is not correct:
  39. but I admit I should have been careful. Those that did not spot my
  40. earlier mistake, please ignore this note as well: it is not something
  41. worth getting confused about.)
  42.  
  43. Cheers
  44. Tanmoy
  45. --
  46. tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
  47. Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
  48. Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
  49. <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
  50. internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
  51. fax: 1 (505) 665 3003   voice: 1 (505) 665 4733    [ Home: 1 (505) 662 5596 ]
  52.